<?php
class MD_Banner
{
	public static function getAll()
	{
		$content = TN_Db::getInstance()->fetchAll("SELECT * FROM banner ");
    	return $content;
	}
	
	
	public static function getEnabledBanners()
	{
		$content = TN_Db::getInstance()->fetchAll("SELECT * FROM banner where enabled = 1");
    	return $content;
	}
	
	public static function getBannerById($id)
	{
		$content = TN_Db::getInstance()->fetchAll("SELECT * FROM banner where id = '$id' ");
    	return $content[0];
	} 

	public static function add( $name, $url, $image, $enabled )
	{
		TN_Db::getInstance()->insert('banner', array('title'=> $name, 'url' => $url,'enabled' => $enabled , 'image' => $image));
	}
	
	public static function update($id, $name, $url, $image, $enabled )
	{
		TN_Db::getInstance()->update('banner', array('title'=> $name, 'url' => $url,'enabled' => $enabled , 'image' => $image), "id = '$id' ");
	}
		
	public static function delete ($id )
	{
		TN_Db::getInstance()->delete('banner', "id = '$id' ");
	}
 	public static function lastId()
    {
    	return TN_Db::getInstance()->lastInsertId('banner');
    }
    
    public static function setImage($id, $img)
    {
    	TN_Db::getInstance()->update('banner', array('image' => $img), "id = '$id' ");
    }
}
?>